*** Sexism and Voting for Women Candidates - BJPS replication do-files
*** US

log using "C:\Users\a15014rs\Dropbox\Sexism and Candidates\Analysis\BJPS replication files\US_log_file.log", replace

** recode 2018 data for previous vote share

cd "C:\Users\a15014rs\Dropbox\Sexism and Candidates\Data"

import excel "USA\MITLab-House_results/1976-2020-house.xls", sheet("1976-2020-house") firstrow clear

* the districts at large seem to be set to "0"
keep if year == 2018

tab state_po if dis == 0 
tostring district, gen (dis) 
replace dis = "AL" if dis == "0"
gen disid = state_po + dis 

* keep only DEM and REP 
drop if writein == 1 

keep year disid party candidate candidatevotes totalvotes 

fre party 
keep if party == "DEMOCRAT" | party == "REPUBLICAN"
gen voteshare = candidatevotes / totalvotes 


keep disid party candidate voteshare 

* Create a variable for candidate 1 or 2 
gen candidates = . 
replace candidates = 1 if party == "DEMOCRAT"
replace candidates = 2 if party == "REPUBLICAN"

label define candidates_label 1 "Candidate 1" 2 "Candidate 2"
label values candidates candidates_label 

* candidate 1 = democrats; candidate 2 = republicans 
tab candidates party 

rename candidate name 

* districts with 2 dem or 2 reps or more 
duplicates tag disid candidates, gen(duplicate)
tab duplicate
tab disid if duplicate == 1


tab  party voteshare if disid == "CA27"
tab  name voteshare if disid == "CA27"
replace candidates = 3 if name == "BRYAN WITT"

tab party voteshare if disid == "CA44"
tab name voteshare if disid == "CA44"
replace candidates = 3 if name == "AJA L BROWN"

tab party voteshare if disid == "CA6"
tab name voteshare if disid == "CA6"
replace candidates = 3 if name == "JRMAR JEFFERSON"

tab party voteshare if disid == "CA8"
tab name voteshare if disid == "CA8" 
replace candidates = 4 if name == "TIM DONNELLY"

tab party voteshare if disid == "LA3"
tab name voteshare if disid == "LA3" & party == "DEMOCRAT"
drop if  name == "LARRY RADER" | name == "VERONE THOMAS"

tab name voteshare if disid == "LA3" & party == "REPUBLICAN"
drop if disid == "LA3" & party == "REPUBLICAN" & name != "CLAY HIGGINS"

tab voteshare name if disid == "LA3"
drop if disid == "LA3" & voteshare < .10 

tab party voteshare if disid == "LA6"
tab name voteshare if disid == "LA6" & party == "DEMOCRAT"
drop if voteshare < .10 & disid == "LA6" & party == "DEMOCRAT"

tab party voteshare if disid == "WA9"
tab name voteshare if disid == "WA9"
replace candidates = 3 if name == "SARAH SMITH"

tab disid if duplicate == 2
tab party if disid == "LA1"
tab name voteshare if disid == "LA1" & party == "DEMOCRAT"
drop if voteshare < .10 & disid == "LA1" & party == "DEMOCRAT"

tab disid if duplicate == 3
tab party if disid == "LA3"


drop duplicate
duplicates tag disid candidates, gen(duplicate)
tab duplicate

* In most cases candidate 1 = democrats; candidate 2 = republican, with the exception of 5 cases where there are 2 people of the same party running 
tab party candidates

gen party_new = candidates 
label define party_new_label 1 "Democrat" 2 "Republican" 3 "Second Dem" 4 "Second Rep"
label values party_new party_new_label
tab party_new party 
drop party
rename party_new party 

tab party 


cd "C:\Users\a15014rs\Dropbox\Sexism and Candidates\Data\USA\STATA datasets"
save "US_2018_results_temp.dta", replace 

keep disid voteshare party candidates 

* Reshape to create winner and distance to winner 
reshape wide voteshare party, i(disid) j(candidates) 

* Winner share for each constituency 
gen winshare = . 
replace winshare = voteshare1 if voteshare1 > voteshare2 
replace winshare = voteshare2 if voteshare2 > voteshare1  
replace winshare = voteshare1 if voteshare1 > voteshare3 
replace winshare = voteshare2 if voteshare2 > voteshare4
* add unopposed
replace winshare = voteshare1 if voteshare2==.
replace winshare = voteshare2 if voteshare1==. 


* Merge to the long format data - now have a dataset with voteshare and winner share per district 
keep disid winshare 
saveold "us2018_winshare.dta", replace  

merge 1:m disid using  "US_2018_results_temp.dta"
sort disid 
drop _merge 

gen winner = 0 
replace winner = 1 if winshare == voteshare
* replace winner = . if winshare == .

gen distance = winshare - voteshare
replace distance = 0 if winner == 1

rename distance distance_2018
rename voteshare share_2018


* check duplicates
 duplicates list party disid

 keep disid party distance_2018 share_2018 


saveold "2018_results_for_merge.dta", replace 

**********************************************************************************************************************************

** Candidates data coding and cleaning, merge to CES data

import excel "C:\Users\a15014rs\Dropbox\Sexism and Candidates\Data\USA\US candidates 16 June 2023.xls", ///
	sheet("house_candidates_2020(1) v2") firstrow clear

* District Name + Code
gen disid = State + District 
sort disid 

gen party_candidate = "D" if party == "Democrats"
replace party_candidate = "R" if party == "Republican"

* Create identifier for district + party
gen disid_party = disid + party_candidate

duplicates list disid_party

* The races where two democrats were running 
* Rename the secondary (losers) to _2 
tab candidates if disid_party == "CA44D"
tab candidates if disid_party == "CA53D"
tab candidates if disid_party == "WA10D"

replace disid_party = "CA44D2" if disid_party == "CA44D" & candidates == "Analilia Joya"
replace disid_party = "CA53D2" if disid_party == "CA53D" & candidates == "Georgette Gomez"
replace disid_party = "WA10D2" if disid_party == "WA10D" & candidates == "Beth Doglio"

* Races where two republicans ran
* Rename the secondary (loser) to _2
tab candidates if disid_party == "LA5R"
replace disid_party = "LA5R2" if disid_party == "LA5R" & candidates == "Lance Harris"


* Duplicates 
duplicates list disid_party 

* Explore the additional duplicates
* Alison Hayden in CWAP data is in CA15 not CA14
tab candidates if disid_party == "CA14R"
replace disid_party = "CA15R" if candidates == "Alison Hayden"
replace District = "15" if candidates == "Alison Hayden"
replace disid = "CA15" if candidates == "Alison Hayden"

* Karen Bass is in CA37 not CA7 according to CWAP and ballotpedia 
tab candidates if disid_party == "CA7D"
replace disid_party = "CA37D" if candidates == "Karen R. Bass"
replace District = "37" if candidates == "Karen R. Bass"
replace disid = "CA37" if candidates == "Karen R. Bass"

* Becky E. Hites is running in Georgia 13th not FL9th according to CWAP and ballotpedia
tab candidates if disid_party == "FL9R"
replace disid_party = "GA13R" if candidates == "Becky E. Hites"
replace District = "13" if candidates == "Becky E. Hites"
replace disid = "GA13" if candidates == "Becky E. Hites"

* Bill Brewster ran for the republicans in district 12, he was disqualified but appeared on ballot
tab candidates if disid_party == "NC13R"
replace disid_party = "NC12R" if candidates == "Billy Joel 'Bill' Brewster, Jr."
replace District = "12" if candidates == "Billy Joel 'Bill' Brewster, Jr."
replace disid = "NC12" if candidates == "Billy Joel 'Bill' Brewster, Jr."

* William Hanson in the file twice, but doesn't show up as a duplicate because the district for the second entry is recorded as N/A
* Drop duplicate
drop if disid=="N/A4"


* no more duplicates
 duplicates list disid_party


drop if State=="N/A"
 

* Rename some variables for easier analysis (consistent with UK)
tab gender 
gen gender_candidate = . 
replace gender_candidate = 1 if gender == "2. Female"
replace gender_candidate = 2 if gender == "1. Male"
label define candidate_label 1 "Female" 2 "Male"
label values gender_candidate candidate_label 
tab gender_candidate, missing


* Descriptives
tab gender_candidate
tab  Incumbent gender_candidate, row miss
tab party gender_candidate, row miss


fre Winnerelecteddefeated 
encode Winnerelecteddefeated, gen(winner)
recode winner 1=0 2=1 3=0 
fre winner 
label define winner_label 0 "Lost" 1 "Won"
label values winner winner_label
tab Winnerelecteddefeated winner, miss

tab party 
fre party 


****************************************
* Merge the 2018 data
* file "2018_results_for_merge.dta"
****************************************

* create a similar party coding (CA44; CA53; WA10) see above, note there are no races with 2 reps here
duplicates list party disid 
encode party, gen(party_new)
replace party_new = 3 if disid_party == "CA44D2" | disid_party == "CA53D2" | disid_party == "WA10D2"
replace party_new = 4 if disid_party == "LA5R2"
tab party party_new  
drop party
rename party_new party
label define party_label_new 1 "Democrat" 2 "Republican" 3 "Second Dem" 4 "Second Rep"
label values party party_label_new 
tab party


cd "C:\Users\a15014rs\Dropbox\Sexism and Candidates\Data\USA\STATA datasets"
saveold "US_candidate_merged.dta", replace 

* Add the 2018 voteshare 

use "US_candidate_merged.dta", clear 

merge 1:1 disid party using "2018_results_for_merge.dta"

* In total 90 (RS - 69) are not merged; 51 (RS - 46) from the master and 39 (RS - 23) from using (2018 results) are not matched. 6 of these observations are 'second rep' and 'second dem' cases that do not align across districts. 
tab party if _merge == 2
tab party if _merge == 1

tab disid if _merge == 2

tab disid party if distance_2018==.



** give median distance if a candidate from that party did not stand in 2018 (excluding winners)
tabstat distance_2018 if winner!=1, stats(mean)
replace distance_2018 = 0.2648549 if distance==.

** set previous vote share to 0 if did not stand in 2018
replace share_2018 = 0 if share_2018==.

** drop cases which are from the 2018 dataset and don't match to 2020
drop if _merge==2&gender_candidate==.

drop _merge

 
* Save candidate data edited

cd "C:\Users\a15014rs\Dropbox\Sexism and Candidates\Data\USA\STATA datasets"
save "US_candidates_final.dta", replace 


************************************************
* Merge the CES Data 
************************************************

* Open the CES data 
use "C:\Users\a15014rs\Dropbox\Sexism and Candidates\Data\USA\CES\CES20_Common_OUTPUT_vv.dta", clear

* Code the district data
gen state = . 
tostring state, replace
replace state = "AL" if inputstate == 1
replace state = "AK" if inputstate == 2
replace state = "AZ" if inputstate == 4 
replace state = "AR" if inputstate == 5
replace state = "CA" if inputstate == 6
replace state = "CO" if inputstate == 8
replace state = "CT" if inputstate == 9
replace state = "DE" if inputstate == 10
replace state = "DC" if inputstate == 11
replace state = "FL" if inputstate == 12
replace state = "GA" if inputstate == 13
replace state = "HI" if inputstate == 15
replace state = "ID" if inputstate == 16
replace state = "IL" if inputstate == 17
replace state = "IN" if inputstate == 18
replace state = "IA" if inputstate == 19
replace state = "KS" if inputstate == 20
replace state = "KY" if inputstate == 21
replace state = "LA" if inputstate == 22
replace state = "ME" if inputstate == 23
replace state = "MD" if inputstate == 24
replace state = "MA" if inputstate == 25
replace state = "MI" if inputstate == 26
replace state = "MN" if inputstate == 27
replace state = "MS" if inputstate == 28
replace state = "MO" if inputstate == 29
replace state = "MT" if inputstate == 30
replace state = "NE" if inputstate == 31
replace state = "NV" if inputstate == 32
replace state = "NH" if inputstate == 33
replace state = "NJ" if inputstate == 34
replace state = "NM" if inputstate == 35
replace state = "NY" if inputstate == 36
replace state = "NC" if inputstate == 37
replace state = "ND" if inputstate == 38
replace state = "OH" if inputstate == 39
replace state = "OK" if inputstate == 40
replace state = "OR" if inputstate == 41
replace state = "PA" if inputstate == 42
replace state = "RI" if inputstate == 44
replace state = "SC" if inputstate == 45
replace state = "SD" if inputstate == 46
replace state = "TN" if inputstate == 47
replace state = "TX" if inputstate == 48
replace state = "UT" if inputstate == 49
replace state = "VT" if inputstate == 50
replace state = "VA" if inputstate == 51
replace state = "WA" if inputstate == 53
replace state = "WV" if inputstate == 54
replace state = "WI" if inputstate == 55
replace state = "WY" if inputstate == 56


gen disid = state + cdid116

** RS edits to make AL district codes consistent with the candidate data
replace disid = "AKAL" if disid=="AK1"
replace disid = "DEAL" if disid=="DE1"
replace disid = "MTAL" if disid=="MT1"
replace disid = "NDAL" if disid=="ND1"
replace disid = "SDAL" if disid=="SD1"
replace disid = "VTAL" if disid=="VT1"
replace disid = "WYAL" if disid=="WY1"

* For the respondent data there were respondents that were incorrectly assigned, remove these in the merged
* data for the vote analysis (they were shown the incorrect congressional candidate)
* Note they are included in the sexism analysis

tab CC20_422r_dk_flag
tab CC20_421r_dk_flag 

drop if CC20_422r_dk_flag == 1
drop if CC20_421r_dk_flag == 1

sort disid


cd "C:\Users\a15014rs\Dropbox\Sexism and Candidates\Data\USA\STATA datasets"
joinby disid using "US_candidates_final.dta", unmatched(both)

** only cases unmatched = District of Columbia
* Drop
drop if _merge==1|_merge==2



tostring caseid, replace

save "US_data.dta", replace 

************************************************************************************************************************************

** Analysis

cd "C:\Users\a15014rs\Dropbox\Sexism and Candidates\"

* Open merged candidate and voter data-set
use "Data\USA\STATA datasets\US_data.dta", clear 

* Indicate whether race is male/male or male/female or female/female
fre gender_candidate

* takes value of 1 if it is a mixed race, value of 2 if just men 
egen women_race = min(gender_candidate), by(disid)

* takes values of 1 if all women race, value of 2 if mixed or just men 
egen women_only = max(gender_candidate), by(disid)

* at least 1 woman in race 
gen sample_races=1 if women_race==1&women_only==2 
replace sample_races=0 if sample_races==.
replace sample_races = . if gender_candidate == . 

**male-female races
codebook disid if sample_races==1
**all-women races
codebook disid if women_race==2
**all-male races
codebook disid if women_only==1

* sample races is just races where there is a man / woman match up, not women only races 
label define sr_label 0 "All men or all women" 1 "Men vs. Woman" 
label values sample_races sr_label

**********************
* 1. Sexism measures
**********************

gen offended = CC20_440d
gen control = CC20_440c
 
alpha offended control  

* there are no DK responses, but there is lots of missing data N = 18.771 (askd of part survey?)
 
 * scale to range - 2 to +2 (positive values = high in sexism)
recode offended 1=5 2=4 3=3 4=2 5=1 
recode offended 1=-2 2=-1 3=0 4=1 5=2
recode control 1=5 2=4 3=3 4=2 5=1
recode control   1=-2 2=-1 3=0 4=1 5=2
label define sexism_label -2 "Strongly disagree" -1 "Disagree" 0 "Neither" 1 "Agree" 2 "Strongly Agree"
label values offended control sexism_label

* Correlation is 0.66
pwcorr offended control, sig 

alpha offended control

* Create scales
* "hostile" = offended and control, ranging -4 to +4
* "hostile_rescale" = offended and control, ranging from -1 to +1
* "hostile_rescale2" = offended and control, ranging from 0 to 2 

* rowtotal 
egen hostile = rowtotal(offended control), missing

* Recode -1 to +1 
gen hostile_rescale = hostile / 4

tab hostile_rescale [aw=commonweight]

** rescale hostile sexism so 0 = least sexist
gen hostile_rescale2 = hostile_rescale+1

gen nothostile=1 if hostile_rescale<0
replace nothostile=0 if hostile_rescale>=0
gen hostile2=1 if hostile_rescale>0
replace hostile2=0 if hostile_rescale<=0


** sample size
codebook caseid if hostile_rescale2!=.
codebook caseid if tookpost==2



***********************
* 2. DV = Votechoice
***********************
 
encode HouseCand1Party, gen(can1_party)
encode HouseCand2Party, gen(can2_party)
rename CC20_412 votechoice1
recode votechoice1 11=3 12=3 10=. 13 =. 
label define vote_label1 1 "Candidate 1" 2 "Candidate 2" 3 "Did not Vote"
label values votechoice1 vote_label1

tab votechoice1 

* Party vote to identify if they voted Rep or Dem 
* can1 party 1 = Democrat ; can2party 2 = Democrat, 5. = Republican 
gen party_vote = . 
replace party_vote = 1 if votechoice1 == 1 & can1_party == 1 | votechoice1 == 2 & can2_party == 2
replace party_vote = 2 if votechoice1 == 2 & can2_party == 5
replace party_vote = 3 if votechoice1 == 1 & can1_party == 2 | votechoice1 == 2 & can2_party == 3
replace party_vote = 4 if votechoice1 == 2 & can2_party == 1 | votechoice1 == 2 & can2_party == 4
replace party_vote = 5 if votechoice1 == 3

label define party_vote_label 1 "Democrat" 2 "Republican" 3 "Independent"  4 "Other Party" 5 "Did not vote"
label values party_vote party_vote_label

tab party_vote 

* match party vote to party candidate 
* this removes non voters
encode(party_candidate), gen(party_candidate1) 
drop party_candidate
rename party_candidate1 party_candidate 

gen vote_choice = 0
replace vote_choice = 1 if party_candidate == 1 & party_vote == 1 | party_candidate == 2 & party_vote == 2 
replace vote_choice = 0 if vote_choice==.
replace vote_choice = . if party_vote==5


* Rename for analysis 
rename caseid id 
recode gender_candidate (2=0) (1=1)
label define genderbinary 0 "men" 1 "women"
label values gender_candidate genderbinary
 
** non-partisan identifers
gen nonpartisan = 0 
replace nonpartisan = 1 if pid7 == 4
replace nonpartisan = . if pid7 == . | pid7 == 8

* Incumbent
encode Incumbent, gen(incumbent)
recode incumbent 1=0 2=1
label define incumbent_label 0 "Not incumbent" 1 "Incumbent"
label values incumbent incumbent_label
tab incumbent 

* Recoding to align with the UK coding
fre gender
recode gender 1=0 2=1 
label define gender_new  0 "Men" 1 "Women"
label values gender gender_new

fre party_candidate
fre party 

gen party_candidate1 = . 
replace party_candidate1 = 1 if party_candidate == 2 | party == 2 | party == 4
replace party_candidate1 = 2 if party_candidate == 1 | party == 1 | party == 3
label define party_label_new2 1 "Republican" 2 "Democrat"
label values party_candidate1 party_label_new2 

drop party party_candidate
rename party_candidate1 party_candidate

save "Data\US_data_recoded.dta", replace


* Set sample
gen fullsample = 1 if gender_candidate !=. & party_candidate!=. & incumbent != . ///
	& distance != . & hostile_rescale != . & vote_choice != . & commonpostweight != . & sample_races == 1 
replace fullsample = 0 if fullsample != 1

** identify respondents with all zeros on vote choice dependent var
clogit vote_choice i.gender_candidate if fullsample==1 & sample_races==1 [pw=commonpostweight], group(id) or
gen wanted=e(sample)
tab wanted

** Keep analytical sample
keep if wanted==1

** sample size
codebook id

** scale reliability for analytical sample
alpha offended control


****************************
* 3.) Vote Models
****************************

cd "C:\Users\a15014rs\Dropbox\Sexism and Candidates"

** Main Models
* Voting for female candidates - with and without controls
set more off
clogit vote_choice i.gender_candidate if fullsample==1 & sample_races==1 [pw=commonpostweight], group(id) or
margins, dydx(gender_candidate) post
est store model_1
outreg using "Output\BJPS resubmission\Table 6 US.doc", replace se or  starlevels (10 5 1)
clogit vote_choice i.gender_candidate i.party_candidate i.incumbent c.distance_2018  ///
	 if fullsample==1&sample_races==1 [pw=commonpostweight], group(id) or 
outreg using "Output\BJPS resubmission\Table 6 US.doc", merge se or  starlevels (10 5 1)
margins, dydx(gender_candidate) post
est store model_2
coefplot (model_1, label("M1 - Without controls")) (model_2, label("M2 - With controls")), title("US") ///
	ytitle("AME voting for female candidate") ylabel("") xline(0) saving("Output\BJPS resubmission\US_table6", replace)


* Voting for women by hostile sexism (controlling for party and sexism )
set more off
clogit vote_choice i.gender_candidate##c.hostile_rescale2 i.party_candidate i.incumbent c.distance_2018 if fullsample==1&sample_races==1 [pw=commonpostweight], group(id)  or 
   outreg using "Output\BJPS resubmission\Table 7 US.doc", replace se or ctitle("", " c.gender*sexism") starlevels (10 5 1)
clogit vote_choice i.gender_candidate##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance_2018 ///
	if fullsample==1&sample_races==1 [pw=commonpostweight], group(id)  or 
 outreg using "Output\BJPS resubmission\Table 7 US.doc", merge se or ctitle("", " c.gender*sexism") starlevels (10 5 1)
 
* Robustness checks
* For men and women
clogit vote_choice i.gender_candidate##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance_2018 ///
	if gender==1&fullsample==1&sample_races==1 [pw=commonpostweight], group(id) or 
outreg using "Output\BJPS resubmission\Robustness checks\gender US.doc", merge se or ctitle("", "women") starlevels (10 5 1)
clogit vote_choice i.gender_candidate##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance_2018 ///
	if gender==0&fullsample==1&sample_races==1 [pw=commonpostweight], group(id) or 
outreg using "Output\BJPS resubmission\Robustness checks\gender US", merge se or ctitle("", "men") starlevels (10 5 1)

 * partisans and non partisans   
clogit vote_choice i.gender_candidate##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance_2018 ///
	if fullsample==1&sample_races==1&nonpartisan==0 [pw=commonweight], group(id)  or 
outreg using "Output\BJPS resubmission\Robustness checks\partisanship US.doc", replace se or ctitle("", " c.partisans") starlevels (10 5 1)
clogit vote_choice i.gender_candidate##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance_2018 ///
	if fullsample==1&sample_races==1&nonpartisan==1 [pw=commonweight], group(id)  or  
outreg using "Output\BJPS resubmission\Robustness checks\partisanship US.doc", merge se or ctitle("", " c.non-partisan") starlevels (10 5 1)

* By party
tab pid7
gen democrat=1 if pid7>=1&pid7<=3
replace democrat=0 if pid7>=4&pid7<=8
gen republican=1 if pid7>=5&pid7<=7
replace republican=0 if pid7>=1&pid7<=4|pid7==8
clogit vote_choice i.gender_candidate##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance_2018 ///
	if fullsample==1&sample_races==1&democrat==1 [pw=commonweight], group(id)  or 
outreg using "Output\BJPS resubmission\Robustness checks\party US.doc", replace se or ctitle("", "c. Democratic identifiers") starlevels (10 5 1)
clogit vote_choice i.gender_candidate##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance_2018 ///
	if fullsample==1&sample_races==1&republican==1 [pw=commonweight], group(id)  or 
outreg using "Output\BJPS resubmission\Robustness checks\party US.doc", merge se or ctitle("", "c. Republican identifiers") starlevels (10 5 1)

* Using "women seek to gain power by getting control over men" (consistent across countries)
clogit vote_choice i.gender_candidate##c.control i.party_candidate##c.control i.incumbent c.distance_2018 ///
	if fullsample==1&sample_races==1 [pw=commonpostweight], group(id)  or 
 outreg using "Output\BJPS resubmission\Robustness checks\control item US.doc", replace se or ctitle("", " c.gender*sexism") starlevels (10 5 1)
 
 ** Vote share in 2018 as a control
 pwcorr distance_2018 share_2018 /** correlation = -0.7825 **/
 
 clogit vote_choice i.gender_candidate i.party_candidate i.incumbent c.share_2018  ///
	 if fullsample==1&sample_races==1 [pw=commonpostweight], group(id) or 
outreg using "Output\BJPS resubmission\Robustness checks\vote share control US.doc", replace se or  starlevels (10 5 1)
clogit vote_choice i.gender_candidate##c.hostile_rescale2 i.party_candidate i.incumbent c.share_2018 if fullsample==1&sample_races==1 [pw=commonpostweight], group(id)  or 
   outreg using "Output\BJPS resubmission\Robustness checks\vote share control US.doc", merge se or ctitle("", " c.gender*sexism") starlevels (10 5 1)
clogit vote_choice i.gender_candidate##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.share_2018 ///
	if fullsample==1&sample_races==1 [pw=commonpostweight], group(id)  or 
 outreg using "Output\BJPS resubmission\Robustness checks\vote share control US.doc", merge se or ctitle("", " c.gender*sexism") starlevels (10 5 1)
  
 ** Table 3 for analytical samople only
collapse hostile2 nothostile [iw=commonpostweight], by(id)

tab nothostile
tab hostile2

  
************
* Turnout 
************

use "Data\US_data_recoded.dta", clear

gen abstain = .
replace abstain = 1 if CL_2020gvm == . 
replace abstain = 0 if CL_2020gvm >=1 & CL_2020gvm != . 


gen age = 2020 - birthyr

gen work_stat = . 
replace work_stat = 1 if employ == 1 
replace work_stat = 2 if employ == 2
replace work_stat = 3 if employ == 3 | employ == 4
replace work_stat = 4 if employ == 5
replace work_stat = 5 if employ == 8
replace work_stat = 6 if employ == 6 | employ == 7 | employ == 9 

label define work_label 1 "Employed fulltime" 2 "Employed parttime" 3 "Unemployed" 4 "Retired" 5 "Student" 6 "Other out of work (incl. homemaker)"
label values work_stat work_label 

gen income = faminc_new
recode income 97=. 
label values income faminc_new

gen union_new = union
recode union_new 2=0 3=0 
rename union union_old
rename union_new union

gen copartisan = 1 if party_candidate == 1 & pid3 == 2 | party_candidate == 2 & pid3 == 1
replace copartisan = 0 if copartisan == .

drop if copartisan==0

encode state, gen(state_factor)
rename state state_old
rename state_factor state 

* Abstention Regression Models 
set more off

cd "C:\Users\a15014rs\Dropbox\Sexism and Candidates\"

logit abstain c.hostile_rescale2##i.gender_candidate i.gender i.educ c.age i.work_stat i.income  c.distance_2018 i.incumbent ///
	i.union i.state [pw=commonpostweight] if sample_races==1 & copartisan == 1
outreg using "Output\BJPS resubmission\Table 8 US.doc", replace se or ctitles("", "Abstention") starlevels (10 5 1)
margins gender_candidate, at(hostile_rescale2=(0(1)2))
marginsplot, ytitle("Probability of abstaining") xtitle("") xlabel(0 "Not sexist (<1)" 1 "Neutral (1)" 2 "Sexist (>1)") ///
	title("US") saving("Output\BJPS resubmission\US_table8", replace)

** Robustness - by party
gen democrat=1 if pid7>=1&pid7<=3
replace democrat=0 if pid7>=4&pid7<=8
gen republican=1 if pid7>=5&pid7<=7
replace republican=0 if pid7>=1&pid7<=4|pid7==8
logit abstain c.hostile_rescale2##i.gender_candidate i.gender i.educ c.age i.work_stat i.income  c.distance_2018 i.incumbent ///
	i.union i.state [pw=commonpostweight] if sample_races==1 & copartisan == 1&democrat==1
outreg using "Output\BJPS resubmission\Robustness checks\party turnout US.doc", replace se or ctitles("", "Democrats") starlevels (10 5 1)
logit abstain c.hostile_rescale2##i.gender_candidate i.gender i.educ c.age i.work_stat i.income  c.distance_2018 i.incumbent ///
	i.union i.state [pw=commonpostweight] if sample_races==1 & copartisan == 1&republican==1
outreg using "Output\BJPS resubmission\Robustness checks\party turnout US", merge se or ctitles("", "Republicans") starlevels (10 5 1)

** Robustness - using "women seek to gain power by getting control over men" 
  logit abstain c.control##i.gender_candidate i.gender i.educ c.age i.work_stat i.income  c.distance_2018 i.incumbent ///
	i.union i.state [pw=commonpostweight] if sample_races==1 & copartisan == 1
outreg using "Output\BJPS resubmission\Robustness checks\control turnout US.doc", replace se or ctitles("", "Abstention") starlevels (10 5 1)
  
** Robustness - controlling for previous vote share
logit abstain c.hostile_rescale2##i.gender_candidate i.gender i.educ c.age i.work_stat i.income  c.share_2018 i.incumbent ///
	i.union i.state [pw=commonpostweight] if sample_races==1 & copartisan == 1
outreg using "Output\BJPS resubmission\Robustness checks\vote share control turnout US.doc", replace se or ctitles("", "Abstention") starlevels (10 5 1)

** Abstention models
use "Data\US_data_recoded.dta", clear 

** 80% turnout in the weighted sample
** Abstainers
gen abstain = .
replace abstain = 1 if CL_2020gvm == . 
replace abstain = 0 if CL_2020gvm >=1 & CL_2020gvm != . 


** Abstainers versus voters on sexism
collapse abstain hostile_rescale [iw=commonpostweight], by(id)
drop if hostile_rescale==.

gen nothostile=1 if hostile_rescale<0
replace nothostile=0 if hostile_rescale>=0
gen hostile2=1 if hostile_rescale>0
replace hostile2=0 if hostile_rescale<=0

tab abstain hostile2, row
tab abstain nothostile, row

log close










